package com.kedacom.ctsp.authority;

import com.kedacom.ctsp.authz.security.AuthzSecurityProperties;
import com.kedacom.ctsp.authz.security.AuthzWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.web.client.RestTemplate;

/**
 * @author: fenghaiju
 * @Date: Created in 9:29 2018/4/25
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(AuthzSecurityProperties.class)
public class WebSecurityConfiguration extends AuthzWebSecurityConfigurerAdapter {

    @Autowired
    private AuthzSecurityProperties securityProperties;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http.formLogin().loginPage(securityProperties.getClientLoginUrl());
    }

    @Bean
    public RestTemplate restTemplate() {

        //restTemplate 设置超时
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        simpleClientHttpRequestFactory.setConnectTimeout(30000);
        simpleClientHttpRequestFactory.setReadTimeout(30000);
        return new RestTemplate(simpleClientHttpRequestFactory);
    }


}